package ch09;

import java.util.Calendar;

class _29_CalendarEx6 {
	public static void main(String[] args) {		
		int year = 2014;
		int month = 9;

		int START_DAY_OF_WEEK = 0;
		int END_DAY = 0;

		Calendar sDay = Calendar.getInstance(); // 시작일
		Calendar eDay = Calendar.getInstance(); // 말일
		
		sDay.set(year, month - 1, 1);
		eDay.set(year, month, 1);		
		eDay.add(Calendar.DATE, -1);

		START_DAY_OF_WEEK = sDay.get(Calendar.DAY_OF_WEEK);	
		END_DAY = eDay.get(Calendar.DATE);

		System.out.println("      " + year + "년 " + month + "월");
		System.out.println(" SU MO TU WE TH FR SA");
		for (int i = 1; i < START_DAY_OF_WEEK; i++) System.out.print("   ");

		for (int i = 1, n = START_DAY_OF_WEEK; i <= END_DAY; i++, n++) {
			System.out.print((i < 10) ? "  " + i : " " + i);
			if (n % 7 == 0)	System.out.println();
		}
	}
}
/*
     2014년 9월
SU MO TU WE TH FR SA
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
*/